var URL = "http://huaer.zanboon.com:9586";//请求地址  http://huaer.zanboon.com:9586
var utoken = "15591284292930013186";//15591284292930013186
var rank_id = '13'
function btnClick(type, title, content){
	console.log("console.log(content);",content);
	if(type === 0){
		if(title === '接单须知'){
			 location.href = "huaer://goOrderInfoPage"
		 }
		 if(title === '等级介绍'){
			 location.href = "huaer://goInfoPage"
		}
		if(title === '降级申诉'){
			 location.href = "huaer://goJiangjiPage"
		}
	}else{
		// location.href = "http://www.baidu.com"
		location.href = content.toString();
		console.log(content);
	}
	// if((i !== '接单须知') || (i !== '降级申诉') || (i !== 'Q&A问答')){
	// 	console.log(location.href = "www.baidu.com");
	// 	location.href = "introduce.html?token=15591284292930013186"
	// }
}

function videourl(i){
	console.log(videourl);
	location.href = "huaer://goVideoPage?http://www.baidu.com"
}

function btnComit(){
	 location.href = "huaer://goTestPage"
}
//获取URL参数 paraName 需要获取的参数名
//paraName 等找参数的名称
function GetUrlParam(paraName) {
　　var url = document.location.toString();
　　var arrObj = url.split("?");
　　if (arrObj.length > 1) {
　　　　var arrPara = arrObj[1].split("&");
　　　　var arr;
　　　　for (var i = 0; i < arrPara.length; i++) {
　　　　　　arr = arrPara[i].split("=");
　　　　　　if (arr != null && arr[0] == paraName) {
　　　　　　　　return arr[1];
　　　　　　}
　　　　}
　　　　return "";
　　}
　　else {
　　　　return "";
　　}
}

//功能按钮
$(document).ready(function(){
	utoken = GetUrlParam('token');
	URL = GetUrlParam('url');
	$.ajax({
		url: URL + "/index/car_article/get_list",
		data:{
			token : utoken,
		},
		type: "GET",
		success(res){
			if(res.status == 0){
				console.log("获取功能按钮失败" + JSON.stringify(res));
			}else{
				var btntpl = document.getElementById("btntpl").innerHTML;
				var blist = res.list;
				// var ulist = ['index.html','new_file.html','test.html?id=938','index.html',]
				console.log(btntpl);
				console.log("blist.length=" + blist.length);
				var btemp = '';
				for (var i = 0; i < blist.length; i++) {
					var btnObj = blist[i]
					btemp += btntpl.replace('@btnName',btnObj.title)
							.replace('@Id', btnObj.id)
							.replace('@bname', btnObj.title)
							.replace('@content', btnObj.content)
							.replace('@type', btnObj.type);
							// .replace('@btnUrl', '#'/* ulist[i].toString() */);
				console.log('id-title-content-type',btnObj.id, btnObj.title,btnObj.content,btnObj.type)
				}
				document.getElementById("funcButton").innerHTML = btemp;
			}
		},
		error(res){
			alert("Request Data Fail");
		}
	});
	
});
//等级认证
$(document).ready(function(){
	utoken = GetUrlParam('token');
	var user_id = GetUrlParam('user_id');
	$('#comit').attr('disabled', 'disabled');
	$('#comit').attr('style', 'background: #787878');
	$.ajax({
		url: URL + "/index/train/trainValidate",
		data:{
			token: utoken,
			user_id: user_id,
		},
		type: "post",
		dataType: "json",
		success(res){
			if(res.status == 0){
				console.log("获取等级信息失败" + JSON.stringify(res));
			}else{
				console.log(res.rank_list);
				// var ranklist = res.data.rank_list;
				var ranklist = res.data.driver_info.course;
				var dinfo = res.data.driver_info;
				var otmpl = document.getElementById("otmpl").innerHTML;
				console.log(otmpl);
				var ohl = '';
				$(ranklist).each(function(){
					var percent = Math.floor((this.order_num/this.min_score) * 100);
					console.log("this.order_num" +this.order_num)
					ohl = otmpl.replace('@order_num',this.order_num)
							.replace('@min_score',this.min_score)
							.replace('@twidth', percent);
					console.log('this.order_num/this.min_score',percent)
					
				});
				document.getElementById("middlebox").innerHTML = ohl;
				$(dinfo).each(function(){
					//考试状态
					if(this.test_status == 1){
						$("#comit").removeAttr("disabled");
						$("#comit").removeAttr("style");
					}
					switch (this.rank_name){
						case '初级':
							$('#btnleave').attr('style',"left: -12.5%");
							$("#leave_line").attr('src','../img/leave_line2.png'); ;
							$('#btnleave').text(this.rank_name);
							break;
						case '中级':
							$('#btnleave').attr('style',"left:12.5%");
							$("#leave_line").attr('src','../img/leave_line3.png');
							$('#btnleave').text(this.rank_name);
							break;
						case '高级':
							$('#btnleave').attr('style',"left:35.5%");
							$("#leave_line").attr('src','../img/leave_line4.png');
							$('#btnleave').text(this.rank_name);
							break;
						default:
							$('#btnleave').attr('style',"left:-36.5%");
							$("#leave_line").attr('src','../img/leave_line.png');
							$('#btnleave').text(this.rank_name);
							break;
					}
				})
			}
		},
		error(res){
			alert("Request Data Fail" + JSON.stringify(res));
		}
	});
});
//获取视频信息
$(document).ready(function(){
	utoken = GetUrlParam('token');
	rank_id = GetUrlParam('rank_id');
	$.ajax({
		url: URL + "/index/train/trainlist",
		data:{
			token: utoken,
			rank_id: rank_id,//13,
		},
		// type: "post",
		// dataType: "json",
		success(res){
			if(res.status == 0){
				console.log("获取视频信息失败" + JSON.stringify(res));
			}else{
				// 获取模板
				var vtmpl = document.getElementById('vtmpl').innerHTML;
				var leavelist = res.list;
				console.log(vtmpl);
				console.log("res.list" + leavelist.length);
				// 解析数据
				var vtemp = '';
				for (var i = 0; i < leavelist.length; i++) {
					console.log("leavelist" + leavelist[i]);
					var obj = leavelist[i];
					if(obj.status == 1) name = "已完成";
					else name = "未完成";
					vtemp += vtmpl.replace('@url',obj.video_url)
						.replace('@name',name)
						.replace('@video_img_url',obj.video_img_url)
						.replace('@video_title',obj.video_title)
						.replace('@vurl', obj.id);
				}
				document.getElementById('videobox').innerHTML = vtemp;
			}
		},
		error(res){
			alert("Request Data Fail" + res)
		}
	});
});



//请求数据
/* $.ajax({
	url: "http://huaer.zanboon.com:9586/index/driver_rank/index",
	// data: {
	// 	token: "QZJHj8mDC9iEhzUq6npg",
	// 	orderStatus: 'obligation',
	// 	merchantID: 1,
	// 	page: 1,
	// 	pagesize: 1
	// },//请求数据
	type: "post",//请求类型
	dataType:'json',//数据类型
	timeout: 100000,//请求超时时间
	success(res){//请求成功的回调
		console.log(JSON.stringify(res.list));
		var leaveList = res.list;
		var vbox = document.getElementsByClassName("v-box");
		 $.each(leaveList, function (n, value) {
               // alert(n + ' ' + value.name);
			   // var img = document.createElement("img");
			   // img.setAttribute("class", "img-responsive");
			   // img.src = "../img/v1.png";
			   // // $("#im").src("../img/v1.png");
			   // $("#v-box").append(img);
			   $('body').append('<div class="clickme">Another target</div>');
			   if(n == 1) {
					var v=$(".v-status").append(value.name);
					
				    $("#v-box").after(v);
			   }
			  
			   if(n == 2){
				   var v1=$(".v-status").append(value.son_id);
				   $("#v-box").after(v1);
			   } 
			  //  
			  //  var dd1= $('<div id="dd1">');
			  //  $(dd1).text("dd1 1dd");
			  //  $("#v-box").append(dd1);
               // var trs = "";
               // trs += "<tr><td>" + value.name + "</td> <td>" + value.password + "</td></tr>";
               // tbody += trs;
           });
		// $(leaveList).function(n,v){
		// 	a
		// });
		
		// var urlObj = JSON.stringify(res.data.url);
		// alert("请求数据成功： " +  dataObj)
		// document.getElementById("im").innerHTML = urlObj;
	},
	error(res){//请求失败的回调
		alert("请求数据失败!");
	}
}); */




/* var parent = document.getElementById("funcButton");
var arr = [
	"等级介绍","接单须知","降级申诉","安全培训",
	"司导管理","奖惩制度","服务流程","服务标准",
	"带客技巧","拍照技巧","沟通技巧","应变能力",
	"Q&A问答","路线介绍","景点介绍"];
for (var i = 0; i < arr.length; i++) {
	var cbtn = document.createElement("button");
	cbtn.setAttribute("class", "btn btn row-xs-3 row-sm-3 row-md-3 row-lg-3");
	cbtn.setAttribute("id", "btn" + i)
	cbtn.innerHTML = arr[i];
	parent.appendChild(cbtn);
}
$('#funcButton').ready(function(){
	
	var s = $('#btn id');
	console.log("s"  + JSON.stringify(s))
}) */

// for(var i=0; i < arr.length; i++){
// 	console.log(parent[i])
// 	// parent[i].addEventListener('click', function(){
// 	// 	alert(i);
// 	// })
// }